
package codeGenerate.custom.converter.impl;

import java.util.ArrayList;
import java.util.List;

import codeGenerate.common.utils.SystemUtils;
import codeGenerate.custom.converter.CustomConverter;
import codeGenerate.custom.vo.CustomPropertyVo;

/**
 * 默认的自定义转换器，将字段字符串转化成类字段集合
 * <p>支持如下格式：</p>
 * <p>医院标示	HOSPITAL	String</p>
 * <p>医院标示	HOSPITAL </p>
 * @author fudewei
 */
public class DefaultCustomConverter implements CustomConverter {

	@Override
	public List<CustomPropertyVo> convert(String fieldStr) {

		List<CustomPropertyVo> list = new ArrayList<>();
		String[] columnlines = fieldStr.trim().split("\n");
		for (String columnline : columnlines) {
			String[] columns = columnline.trim().split("\\s+");
			CustomPropertyVo packageColumnVo = new CustomPropertyVo();
			packageColumnVo.setJavaPropertyComment(columns[0]);
			packageColumnVo.setJavaPropertyName(SystemUtils.dbColumnNameNameToJavaPropertyName(columns[1]));
			packageColumnVo.setOrginalPropertyName(columns[1]);
			if (columns.length == 3) {
				packageColumnVo.setJavaPropertyType(columns[2]);
			} else {
				//不指定类型，默认String
				packageColumnVo.setJavaPropertyType("String");
			}

			list.add(packageColumnVo);
		}
		return list;
	}

}
